home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / misc / football / exec / writematch.rexx < prev   
OS/2 REXX Batch file  |  1999-02-03  |  4KB  |  139 lines

  1. /* ***********************************************************************
  2.  
  3.    WRITE MATCH PROGRAM FOR FOOTBALL REXX SUITE
  4.   ---------------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       080597   Created. Designed to be called from Gameplay to write
  12.                     the score directly to the Schedule file, giving an
  13.                     error if the match has been played, leaving Gameplay
  14.                     to update the Learn file.
  15.            100597   Changed command for deleting the Game.Stored file. Had
  16.                     to set 'sdcount' to 1 as lines were being missed in the
  17.                     recreation as the first was being stored at 0 instead
  18.                     of 1 which was where the loop started. Had to amend
  19.                     the loop which wrote it back as it added one extra
  20.                     line which wasn't required. Swapped parameters in the
  21.                     'pos' statement when checking the matches as it was
  22.                     always overwriting matches that had been played.
  23.            100697   Changed position that the away team is picked from the
  24.                     argument to 1 from 2. Was giving invalid values.
  25.                     Changed method again, a draw meant that the positions
  26.                     picked up were one out as it went for the 1st occurrence.
  27.  
  28. **************************************************************************
  29.  
  30. Procedure
  31. ---------
  32.  
  33. 1. Split argument into league-name and match.
  34. 2. Check schedule file exists. If file-indicator exists then erase it.
  35. 3. Split match into home and away teams and their scores.
  36. 4. Read Schedule file into an array.
  37. 5. Search array for the match supplied and if found, overwrite the scores.
  38. 6. If a match has been played and updated, then rewrite the Schedule file
  39.    back. Then write the file-indicator to tell Gameplay that a match has
  40.    been stored. Then exit.
  41.  
  42. ************************************************************************** */
  43. PARSE ARG league_file
  44.  
  45. version      = 1
  46. input_file   = '.sf'
  47. output_file  = 'RAM:Game.stored'
  48. separator    = '*'
  49. sdlines.     = '???'
  50. sdcount      = 1
  51. not_played   = '__   __'
  52. league_file  = "Data/" || league_file
  53.  
  54. parse var league_file league " " match
  55.  
  56. if exists(league || input_file) = 0  then exit
  57. if exists(output_file) > 0 then
  58.    address command 'delete >NIL: 'output_file
  59.  
  60. do i=1 to words(match)
  61.    if datatype(word(match,i)) = 'NUM' then do
  62.       goalsh = word(match,i)
  63.       goalsa = word(match,i+1)
  64.       placeh = find(match,goalsh) - 1
  65.       placea = find(match,goalsh) + 2
  66.       teamh  = subword(match,1,placeh)
  67.       teama  = subword(match,placea)
  68.       leave
  69.    end
  70. end
  71.  
  72. if open(datafile3,league || input_file,'r') then do
  73.    do while ~eof(datafile3)
  74.       line = readln(datafile3)
  75.       line = strip(line)
  76.       sdlines.sdcount = line
  77.       sdcount         = sdcount + 1
  78.    end
  79.    close(datafile3)
  80. end
  81. else do
  82.    say
  83.    say "ERROR :    (WriteMatch)"
  84.    say
  85.    say "Cannot open '"league || input_file"' for reading."
  86.    exit
  87. end
  88.  
  89. marker = 0
  90. do i=1 to sdcount
  91.    if pos(sdlines.i,separator) = 0 then do
  92.       if find(sdlines.i,teamh) = 1 then do
  93.          if find(sdlines.i,teama) > 1 then do
  94.             if pos(not_played,sdlines.i) > 0 then do
  95.                sdlines.i = overlay(right(goalsh,2),sdlines.i,32)
  96.                sdlines.i = overlay(right(goalsa,2),sdlines.i,37)
  97.                marker = 1
  98.                leave
  99.             end
  100.             else
  101.                marker = 0
  102.          end
  103.       end
  104.    end
  105. end
  106.  
  107. if marker = 1 then do
  108.    if open(datafile3,league || input_file,'w') then do
  109.       do i=1 to sdcount-1
  110.          if i < sdcount-1 then
  111.             writeln(datafile3,sdlines.i)
  112.          else
  113.             writech(datafile3,sdlines.i)
  114.       end
  115.       close(datafile3)
  116.       if open(datafile1,output_file,'w') then do
  117.          writeln(datafile1,"Game stored in '"league||input_file"'.")
  118.          close(datafile1)
  119.       end
  120.       else do
  121.          say
  122.          say "ERROR :    (WriteMatch)"
  123.          say
  124.          say "Match has been stored but the indicator file could not be"
  125.          say "created."
  126.          exit
  127.       end
  128.    end
  129.    else do
  130.       say
  131.       say "ERROR :    (WriteMatch)"
  132.       say
  133.       say "Cannot open '"league || input_file"' for writing."
  134.    end
  135. end
  136.  
  137. exit
  138.  
  139. /* *********************************************************************** */